﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace utd_hrrs
{
    public partial class user02 : System.Web.UI.Page
    {
        SqlConnection conn;
        String usr;
        public String currentDate;
        //String tempcommand;

        protected void Page_Load(object sender, EventArgs e)
        {

            currentDate = DateTime.Now.ToString("M/d/yyyy");

            usr = Request.Cookies["username"].Value;
            userID.Text = usr;
            
            conn = new SqlConnection("Data Source=rockstar.hopto.org,11433;Initial Catalog=UTD_HRRS;Persist Security Info=True;User ID=utd_hrrs;Password=bhowmik6360");

        }


        protected void InsertTentativeReservation(object sender, EventArgs e)
        {
            conn.Open();
            DateTime stdt = new DateTime(Calendar1.SelectedDate.Year, Calendar1.SelectedDate.Month, Calendar1.SelectedDate.Day, int.Parse(ddList_sh.SelectedValue), int.Parse(ddList_sm.SelectedValue), 0);
            DateTime edt = new DateTime(Calendar2.SelectedDate.Year, Calendar2.SelectedDate.Month, Calendar2.SelectedDate.Day, int.Parse(ddList_eh.SelectedValue), int.Parse(ddList_em.SelectedValue), 0);
            //SqlCommand command2 = new SqlCommand("SELECT CASE WHEN DATEDIFF(minute, CONVERT(datetime, " + ddList_sh.SelectedValue + ":" + ddList_sm.SelectedValue + ", 108) + " + Calendar1.SelectedDate.ToString() + ", CONVERT(datetime, " + ddList_eh.SelectedValue + ":" + ddList_em.SelectedValue + ", 108) + " + Calendar2.SelectedDate.ToString() + ")>1 THEN 'YES' ELSE 'NO' END FROM RESERVATION", conn);
            String c1 = "INSERT INTO RESERVATION (START_DATE, END_DATE, START_TIME, END_TIME, USER_ID, INV_ID, PMT_ID, STATUS_ID, START_DATETIME, END_DATETIME)" +
                "VALUES ('" + Calendar1.SelectedDate.ToString() + "', '" + Calendar2.SelectedDate.ToString() + "', '" + ddList_sh.SelectedValue + ":" + ddList_sm.SelectedValue + 
                "', '" + ddList_eh.SelectedValue + ":" + ddList_em.SelectedValue + "', '"+ usr +"', (SELECT TOP 1 INV_ID FROM INVENTORY WHERE EQUIP_TYPE='" + DropDownList1.Text 
                + "'), 1, 1, '" + stdt + "', '" + edt + "')";
            SqlCommand command1 = new SqlCommand(c1, conn);
            int ra = command1.ExecuteNonQuery();

            myLabel.Visible = true;
            myLabel.Text = "The reservation has been made";
            //myLabel.Text = c1;
            //Response.Redirect("user02.aspx");


        }



    protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
        e.Command.Parameters["@usr2"].Value = usr;
    }

    protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {

    }

    protected void AddMyRes(object sender, EventArgs e)
    {

    }

    }
}